package com.mtoanmy.lstviewmultichoice;


import java.util.HashMap;
import java.util.List;

import com.mtoanmy.data.ObjItems;
import com.mtoanmy.myframework.R;

import climaxi.climaxicomic.lazyloadimage.ImageLoader;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ItemsListMultiChoice extends RelativeLayout {

	private Context mContext;
	private Display display;
	private int width;
	private ImageLoader imageLoader;
	private ImageView img_avatar;
	private TextView txt_time;
	private TextView txt_desc;
	private ImageView img_photo;
	private ImageLoader imageLoaderImg;
	private int height;
	private float density;

	public ItemsListMultiChoice(Context context,Activity mActivity) {
		super(context);
		// TODO Auto-generated constructor stub

		LayoutInflater inflater = (LayoutInflater) this.getContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		display = mActivity.getWindowManager().getDefaultDisplay();
		width = display.getWidth();
		height = display.getHeight();
		density= getResources().getDisplayMetrics().density;
		
		mContext = context;
		
		inflater.inflate(R.layout.items_photo, this, true);

		imageLoader = new ImageLoader(mContext);
		imageLoaderImg = new ImageLoader(mContext);
		
		initLayout();
		//checkDensity();
	}
	
	public void checkDensity()
	{
		// return 0.75 if it's LDPI
		// return 1.0 if it's MDPI
		// return 1.5 if it's HDPI
		// return 2.0 if it's XHDPI

		float density= getResources().getDisplayMetrics().density;
		if(density == 0.75)
		{
			txt_time.setTextSize(10);
			txt_desc.setTextSize(10);
		}
		if(density == 1.0)
		{
			txt_time.setTextSize(15);
			txt_desc.setTextSize(15);
		}
		if(density == 1.5)
		{
			txt_time.setTextSize(12);
			txt_desc.setTextSize(12);
		}
		if(density == 2.0)
		{
			txt_time.setTextSize(12);
			txt_desc.setTextSize(12);
		}
	}

	private void initLayout() {
		// TODO Auto-generated method stub
	/*	txt_time = (TextView)findViewById(R.id.txt_time);
		txt_desc = (TextView)findViewById(R.id.txt_desc);
		img_avatar = (ImageView)findViewById(R.id.img_avatar);
		img_photo = (ImageView)findViewById(R.id.img_photo);*/
	}
	
	public void setImageView(int w, int h)
	{
		//Log.v("TEST", "w: " + w + " h: " + h);
		if (w > width && h > height)
		{
			img_photo.getLayoutParams().height = h;
			img_photo.getLayoutParams().width = w;
		}else{
			/*img_photo.getLayoutParams().height = height;
			img_photo.getLayoutParams().width = width;
			img_photo.setScaleType(ScaleType.FIT_XY);*/
			float percent = (float)((float)(width)/(float)(w));
			img_photo.getLayoutParams().width = (int) Math.round(w*percent);
			img_photo.getLayoutParams().height = (int) Math.round(h*percent);

			//Log.v("TEST", "wNew: " + img_photo.getLayoutParams().width + " hNew: " + img_photo.getLayoutParams().height + " percent: " + percent);
			//img_photo.setScaleType(ScaleType.FIT_XY);
		}
		
	}

	public void addData(ObjItems data)
	{
		/*setImageView(Integer.parseInt(data.getW()), Integer.parseInt(data.getH()));
		txt_time.setText(data.getTime());
		txt_desc.setText(data.getDesc());
		imageLoader.DisplayImage(data.getThumb(), img_avatar);
		imageLoaderImg.DisplayImage(data.getImg(), img_photo);*/

	}
}
